home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SimpleVideoOut.c
-
- Description: SimpleVideoOut is an example of using QuickTimes FireWire video
- output component to play a DV stream (.dv movie) out to a DV Camera.
- This code is based on VidOutApp originally written by Jay Lloyd, Casey King
- and Adrienne Wang.
-
- Author: era
-
- Copyright: © Copyright 2000 Apple Computer, Inc. All rights reserved.
-
- Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
- ("Apple") in consideration of your agreement to the following terms, and your
- use, installation, modification or redistribution of this Apple software
- constitutes acceptance of these terms. If you do not agree with these terms,
- please do not use, install, modify or redistribute this Apple software.
-
- In consideration of your agreement to abide by the following terms, and subject
- to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
- copyrights in this original Apple software (the "Apple Software"), to use,
- reproduce, modify and redistribute the Apple Software, with or without
- modifications, in source and/or binary forms; provided that if you redistribute
- the Apple Software in its entirety and without modifications, you must retain
- this notice and the following text and disclaimers in all such redistributions of
- the Apple Software. Neither the name, trademarks, service marks or logos of
- Apple Computer, Inc. may be used to endorse or promote products derived from the
- Apple Software without specific prior written permission from Apple. Except as
- expressly stated in this notice, no other rights or licenses, express or implied,
- are granted by Apple herein, including but not limited to any patent rights that
- may be infringed by your derivative works or by other works in which the Apple
- Software may be incorporated.
-
- The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
- WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
- WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
- COMBINATION WITH YOUR PRODUCTS.
-
- IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
- OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
- (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- Change History (most recent first): <1> 1/28/00 initial release
-
- */
-
- #include <Movies.h>
- #include <QuickTimeComponents.h>
- #include <MacWindows.h>
- #include <Gestalt.h>
- #include <ToolUtils.h>
-
- #include "CVideoOutput.h"
-
- using namespace dts;
-
- const short kAlert = 128;
- const short kPopUpMenu = 129;
- const short kEchoOnID = 1;
- const short kEchoOffID = 2;
- const short kVOSoundOnID = 4;
- const short kVOSoundOffID = 5;
-
- // Globals
- static WindowRef gWindow = NULL;
- static Movie gMovie = NULL;
- static MovieController gController = NULL;
- static MenuHandle gPopUpMenuHandle = NULL;
- static short gMCHeight = 0;
-
- static Boolean gDone = false;
-
- void main( void );
- void Initialize( void );
- OSErr DoOpenMovieFromFile( FSSpec *inFSSpec );
- OSErr DoCreateMovieController( CVideoOutput *inVideoOutputPtr );
- static pascal Boolean myMCActionFilterWithRefConProc( MovieController theMC, short theAction, void *theParams, long theRefCon );
-
- void Initialize( void )
- {
- long result;
-
- InitGraf( &qd.thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( nil );
- InitCursor();
- FlushEvents( everyEvent, 0 );
-
- // Check for QuickTime
- if ( Gestalt( gestaltQuickTime, &result ) != noErr) {
- ParamText( "\pQuickTime is not installed...", NULL, NULL, NULL );
- StopAlert( kAlert, NULL );
- ExitToShell();
- }
-
- // Initialize all the needed managers
- MaxApplZone();
- for ( UInt8 i = 0; i < 4; i++ ) {
- MoreMasters();
- }
-
- EnterMovies();
-
- // Setup default menu options
- gPopUpMenuHandle = GetMenu( kPopUpMenu );
- if ( gPopUpMenuHandle == NULL ) {
- ParamText( "\pCould not load menu resource...", NULL, NULL, NULL );
- StopAlert( kAlert, NULL );
- ExitToShell();
- }
-
- InsertMenu( gPopUpMenuHandle, -1 );
- CheckItem( gPopUpMenuHandle, kEchoOnID, true );
- CheckItem( gPopUpMenuHandle, kEchoOffID, false );
- CheckItem( gPopUpMenuHandle, kVOSoundOnID, true );
- CheckItem( gPopUpMenuHandle, kVOSoundOffID, false );
- }
-
- OSErr DoOpenMovieFromFile( FSSpec *inFSSpec )
- {
- Rect theWindowRect = { 50, 20, 300, 300 };
- Rect theMovieBox;
- short theMovieRefNum;
-
- OSErr rc = noErr;
-
- // Open the movie file and create our window but don't show it yet
- rc = OpenMovieFile( inFSSpec, &theMovieRefNum, fsRdPerm );
- if ( rc ) return rc;
-
- rc = NewMovieFromFile( &gMovie, theMovieRefNum, NULL, NULL, newMovieActive, NULL );
-
- CloseMovieFile( theMovieRefNum );
- if ( rc ) return rc;
-
- gWindow = NewCWindow( nil, &theWindowRect, inFSSpec->name, false, kWindowFloatProc, (WindowPtr)-1, true, 0 );
- if ( gWindow == NULL ) return -1;
-
- SetPort( gWindow );
-
- GetMovieBox( gMovie, &theMovieBox );
- OffsetRect( &theMovieBox, -theMovieBox.left, -theMovieBox.top );
- SetMovieBox( gMovie, &theMovieBox );
-
- SetMovieGWorld( gMovie, (CGrafPtr)gWindow, NULL );
-
- return rc;
- }
-
- OSErr DoCreateMovieController( CVideoOutput *inVideoOutputPtr )
- {
- Rect theMovieBox;
- long mcFlags;
-
- OSErr rc = noErr;
-
- // Create the movie controller
- GetMovieBox( gMovie, &theMovieBox );
- gMCHeight = theMovieBox.bottom;
-
- gController = NewMovieController( gMovie, &theMovieBox, 0L | mcTopLeftMovie );
- if ( gController == nil) return -1;
-
- // Enable keys and give us a custom button
- MCDoAction( gController, mcActionSetKeysEnabled, (Ptr)true );
- MCDoAction( gController, mcActionGetFlags, &mcFlags );
- MCDoAction( gController, mcActionSetFlags, (Ptr)( mcFlags | mcFlagsUseCustomButton ));
-
- rc = MCGetControllerBoundsRect( gController, &theMovieBox );
- if ( rc ) return rc;
- gMCHeight = theMovieBox.bottom - gMCHeight;
-
- // Resize and show the move window which now contains the attached controller
- SizeWindow( gWindow, theMovieBox.right, theMovieBox.bottom, true );
- ShowWindow( gWindow );
-
- // Install an action filter for application-specific mc action processing
- // This is where the CustomButton actions are handled, we pass in a pointer to
- // our VideoOutput object so we can change it's settings as the custom options are chosen
- MCSetActionFilterWithRefCon( gController, NewMCActionFilterWithRefConProc(myMCActionFilterWithRefConProc), (long)inVideoOutputPtr );
-
- return rc;
- }
-
- static pascal Boolean myMCActionFilterWithRefConProc( MovieController theMC, short theAction, void *theParams, long theRefCon )
- {
- #pragma unused( theParams )
-
- Boolean isHandled = false;
-
- CVideoOutput *pVideoOutput = (CVideoOutput *)theRefCon;
- if ( pVideoOutput == NULL )
- return isHandled;
-
- switch ( theAction ) {
- case mcActionCustomButtonClick:
- Rect theWindowBoundsRect, theMCBoundsRect;
-
- // Calculate the position for the CustomButton pop-up menu
- RgnHandle theRgn = NewRgn();
- GetWindowStructureRgn( gWindow, theRgn );
- theWindowBoundsRect = (**theRgn).rgnBBox;
- DisposeRgn( theRgn );
-
- MCGetControllerBoundsRect( theMC, &theMCBoundsRect );
- LocalToGlobal( (Point *)&theMCBoundsRect.bottom );
-
- // Handle the menu selections and settings
- long theResult = PopUpMenuSelect( gPopUpMenuHandle, theMCBoundsRect.bottom - gMCHeight, theWindowBoundsRect.right + 1, 0 );
- short theItem = LoWord( theResult );
-
- switch ( theItem ) {
- case kEchoOnID:
- CheckItem( gPopUpMenuHandle, kEchoOnID, true );
- CheckItem ( gPopUpMenuHandle, kEchoOffID, false );
- pVideoOutput->SetEchoPort( (CGrafPtr)gWindow );
- break;
- case kEchoOffID:
- CheckItem( gPopUpMenuHandle, kEchoOnID, false );
- CheckItem ( gPopUpMenuHandle, kEchoOffID, true );
- pVideoOutput->SetEchoPort();
- break;
- case kVOSoundOnID:
- CheckItem( gPopUpMenuHandle, kVOSoundOnID, true );
- CheckItem( gPopUpMenuHandle, kVOSoundOffID, false );
- pVideoOutput->SetSoundDevice();
- break;
- case kVOSoundOffID:
- CheckItem( gPopUpMenuHandle, kVOSoundOnID, false );
- CheckItem( gPopUpMenuHandle, kVOSoundOffID, true );
- pVideoOutput->SetSoundDevice( false );
- break;
-
- default:
- break;
- } // switch
-
- isHandled = true;
- break;
-
- default:
- break;
-
- } // switch
-
- return isHandled;
- }
-
- void main( void )
- {
- EventRecord theEvent;
- WindowRef theFoundWindow;
- short theWindowPart;
- ComponentResult isEventHandled;
- SFTypeList theTypeList = { MovieFileType, 0, 0, 0 };
- StandardFileReply theReply;
-
- OSErr rc = noErr;
-
- CVideoOutput *pVideoOutput = NULL;
-
- Initialize();
-
- StandardGetFilePreview( nil, 1, theTypeList, &theReply );
- if ( !theReply.sfGood ) goto bail;
-
- rc = DoOpenMovieFromFile( &theReply.sfFile );
- if ( rc ) { ParamText( "\pProblem opening movie from file...", NULL, NULL, NULL ); goto bail; }
-
- // Instantiate a VideoOutput object
- pVideoOutput = new CVideoOutput( gMovie );
- if ( pVideoOutput == NULL ) rc = memFullErr;
- if ( rc || ( rc = pVideoOutput->GetError() ) != noErr ) { ParamText( "\pProblem initializing CVideoOutput, or FireWire component unavailable...", NULL, NULL, NULL ); goto bail; }
-
- rc = DoCreateMovieController( pVideoOutput );
- if ( rc ) { ParamText( "\pProblem creating movie controller.", NULL, NULL, NULL ); goto bail; }
-
- // Open the component - pass in the client name and the display mode, for our purposes
- // we're going with the default mode '1' which is the ever popular 'NTSC'
- rc = pVideoOutput->Open( "\pSimpleVideoOut", 1 );
- if ( rc ) { ParamText( "\pUnable to sucessfully open the video output component...", NULL, NULL, NULL ); goto bail; }
-
- // Begin the video output, both sound and clock options are set to true in the interface by default
- rc = pVideoOutput->Begin();
- if ( rc ) { ParamText( "\pAttempting to get exclusive access to hardware failed...", NULL, NULL, NULL ); goto bail; }
-
- // The echo port is our main window
- pVideoOutput->SetEchoPort( (CGrafPtr)gWindow );
-
- while (!gDone ) {
-
- if ( WaitNextEvent( everyEvent, &theEvent, 5, NULL ) ) {
-
- if ( gController )
- isEventHandled = MCIsPlayerEvent( gController, &theEvent );
-
- if ( !isEventHandled ) {
- switch ( theEvent.what ) {
- case mouseDown:
- theWindowPart = FindWindow( theEvent.where, &theFoundWindow );
-
- switch ( theWindowPart ) {
- case inDrag:
- DragAlignedWindow( theFoundWindow, theEvent.where, &qd.screenBits.bounds, NULL, NULL );
- break;
- case inGoAway:
- gDone = TrackGoAway( theFoundWindow, theEvent.where );
- pVideoOutput->End();
- break;
- default:
- break;
- } // switch
- break;
- case updateEvt:
- // Handle update events for window.
- theFoundWindow = (WindowPtr)theEvent.message;
- if ( theFoundWindow == gWindow ) {
- BeginUpdate( theFoundWindow );
- UpdateMovie( gMovie );
- SetPort( theFoundWindow );
- EraseRect( &theFoundWindow->portRect );
- MCDraw( gController, gWindow );
- EndUpdate( theFoundWindow );
- }
- break;
- case osEvt:
- if ( ( theEvent.message & ( suspendResumeMessage << 24 )) != 0 ) {
- if ( ( theEvent.message & resumeFlag ) != 0 ) {
- MCDraw( gController, gWindow );
- }
- }
- break;
-
- default:
- break;
- } // switch
- }
- } else {
- MCIdle( gController );
- }
- } // while
-
- bail:
- if ( rc ) StopAlert( kAlert, NULL );
-
- if ( pVideoOutput ) {
- delete pVideoOutput;
- }
-
- if ( gController != NULL )
- DisposeMovieController( gController );
-
- if ( gMovie != NULL )
- DisposeMovie( gMovie );
-
- if ( gWindow != NULL )
- DisposeWindow( gWindow );
-
- ExitMovies();
- }